self.images = []
self.timeout = -1
self._default = 0
+ self.passwordAccess = True
if fn is not None:
self.parse()
if self.commands.has_key(com):
if self.commands[com] is not None:
setattr(self, self.commands[com], arg.strip())
+ #print "%s = %s => %s" % (com, self.commands[com], arg.strip() )
else:
logging.info("Ignored directive %s" %(com,))
else:
if len(img) > 0:
self.add_image(GrubImage(img))
+ if self.hasPassword():
+ self.setPasswordAccess(False)
+
+ def hasPasswordAccess(self):
+ return self.passwordAccess
+
+ def setPasswordAccess(self, val):
+ self.passwordAccess = val
+
+ def hasPassword(self):
+ try:
+ getattr(self, self.commands['password'])
+ return True
+ except KeyError, e:
+ return False
+
+ def checkPassword(self, password):
+ try:
+ pwd = getattr(self, self.commands['password']).split()
+ if pwd[0] == '--md5':
+ import crypt
+ if crypt.crypt(password, pwd[1]) == pwd[1]:
+ return True
+
+ if pwd[0] == password:
+ return True
+
+ return False
+ except:
+ return True
+
def set(self, line):
(com, arg) = grub_exact_split(line, 2)
if self.commands.has_key(com):
self.text_win.addstr(0, 0, "Use the U and D keys to select which entry is highlighted.")
self.text_win.addstr(1, 0, "Press enter to boot the selected OS. 'e' to edit the")
self.text_win.addstr(2, 0, "commands before booting, 'a' to modify the kernel arguments ")
- self.text_win.addstr(3, 0, "before booting, or 'c' for a command line.")
+
+ # if grub has password defined we allow option to enter password
+ if not self.cf.hasPassword():
+ self.text_win.addstr(3, 0, "before booting, or 'c' for a command line.")
+ else:
+ self.text_win.addstr(3, 0, "before booting, or 'c' for a command line. You can also")
+ self.text_win.addstr(4, 0, "press 'p' to enter password for modifications...")
+
self.text_win.addch(0, 8, curses.ACS_UARROW)
self.text_win.addch(0, 14, curses.ACS_DARROW)
(y, x) = self.text_win.getmaxyx()
# handle keypresses
if c == ord('c'):
+ # we disallow access without password specified
+ if not self.cf.hasPasswordAccess():
+ self.text_win.addstr(6, 8, "You have to enter GRUB password first")
+ break
+
self.command_line_mode()
break
elif c == ord('a'):
+ # we disallow access without password specified
+ if not self.cf.hasPasswordAccess():
+ self.text_win.addstr(6, 8, "You have to enter GRUB password first")
+ break
+
# find the kernel line, edit it and then boot
img = self.cf.images[self.selected_image]
for line in img.lines:
break
break
elif c == ord('e'):
+ # we disallow access without password specified
+ if not self.cf.hasPasswordAccess():
+ self.text_win.addstr(6, 8, "You have to enter GRUB password first")
+ break
+
img = self.cf.images[self.selected_image]
self.edit_entry(img)
break
+ elif c == ord('p') and self.cf.hasPassword():
+ self.text_win.addstr(6, 8, "Enter password: ")
+ pwd = self.text_win.getstr(6, 8)
+ if not self.cf.checkPassword(pwd):
+ self.text_win.addstr(6, 8, "Incorrect password!")
+ self.cf.setPasswordAccess( False )
+ else:
+ self.text_win.addstr(6, 8, "Access granted ")
+ self.cf.setPasswordAccess( True )
+ break
elif c in (curses.KEY_ENTER, ord('\n'), ord('\r')):
self.isdone = True
break